package com.wicket.okrapp.biz.service.nb;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.wicket.okrapp.biz.service.dto.common.PicMultipleSetDataEntryDto;
import com.wicket.okrapp.common.baseinfo.BaseInfoDO;
import com.wicket.okrapp.common.baseinfo.BaseInfoHolder;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrcomponent.integration.FwCompTemplateEngineClient;
import com.wicket.okrcomponent.integration.dto.QuerySemanticEngineDetailReqDto;
import com.wicket.okrcomponent.integration.dto.QuerySemanticEngineDetailRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrapp.biz.service.dto.req.ImplementAcceptFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementAcceptFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementAcceptFieldByStandardDataReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementAcceptFieldByStandardDataRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementBizPublicFieldPushMemoryReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementBizPublicFieldPushMemoryRespDto;
import com.wicket.okrapp.biz.service.dto.req.GenerateSemanticContentReqDto;
import com.wicket.okrapp.biz.service.dto.res.GenerateSemanticContentRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementTypeCodeFieldsAcceptReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementTypeCodeFieldsAcceptRespDto;
import com.wicket.okrapp.biz.service.dto.req.ObtainReceiveFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ObtainReceiveFieldRespDto;

import javax.annotation.Resource;
import com.wicket.okrapp.biz.service.dto.req.ImplementGainInParameterFieldsReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementGainInParameterFieldsRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementObtainPageTotalsReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementObtainPageTotalsRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementSendMsgReceiverAcceptFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementSendMsgReceiverAcceptFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementAcceptFieldUseWorkTaskReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementAcceptFieldUseWorkTaskRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementFourthReceivingFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementFourthReceivingFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementElevenReceivingFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementElevenReceivingFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementEightReceivingFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementEightReceivingFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementPicMultipleSetDataEntryReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementPicMultipleSetDataEntryRespDto;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbWorkTasks {

    @Resource
    private FwCompTemplateEngineClient fwCompTemplateEngineClient;
/**
      * code:receptionService
      * name:M3执行接收工作任务类型
      * desc:undefined
      * gen by moon at 11/8/2023, 3:54:33 PM
      * 
      **/
     @Trace(operationName = "M3执行接收工作任务类型")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAcceptFieldRespDto implementAcceptField(ImplementAcceptFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementAcceptFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:约定：任务督办相关
      * desc:undefined
      * gen by moon at 11/8/2023, 3:55:07 PM
      * 
      **/
     @Trace(operationName = "约定：任务督办相关")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAcceptFieldByStandardDataRespDto implementAcceptFieldByStandardData(ImplementAcceptFieldByStandardDataReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementAcceptFieldByStandardDataRespDto.class);
      }
/**
      * code:publicFieldCache
      * name:M3-将工作任务公共字段推送内存
      * desc:undefined
      * gen by moon at 11/10/2023, 4:05:07 AM
      *
      **/
     @Trace(operationName = "M3-将工作任务公共字段推送内存")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementBizPublicFieldPushMemoryRespDto implementBizPublicFieldPushMemory(ImplementBizPublicFieldPushMemoryReqDto reqDto) {
         BaseInfoDO domain = new BaseInfoDO();
         if(BaseInfoHolder.contextHolder.get()!=null){
             BeanUtil.copyProperties(BaseInfoHolder.contextHolder.get().getBaseInfo(),domain);
             BaseInfoHolder.contextHolder.remove();
         }
         if(reqDto.getSpaceId()!=null){
             domain.setSpecSpaceId(reqDto.getSpaceId());
         }

         if(reqDto.getCreateInductionId()!=null){
             domain.setSpecInductionRecordId(reqDto.getCreateInductionId());
         }

         if(reqDto.getAppId()!=null){
             domain.setSpecAppId(reqDto.getAppId());
         }

         CommonFunctionHelper.setBaseInfoToLocal(domain);
         return new ImplementBizPublicFieldPushMemoryRespDto();
      }
/**
      * code:generateSemanticInstance
      * name:M3-生成“剩**小时就逾期”语义内容
      * desc:undefined
      * gen by moon at 11/10/2023, 4:05:08 AM
      *
      **/
     @Trace(operationName = "M3-生成“剩**小时就逾期”语义内容")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public GenerateSemanticContentRespDto createOverdueBurningTimeContent(GenerateSemanticContentReqDto reqDto) {
         boolean bRetFlag = false;
         GenerateSemanticContentRespDto retData = new GenerateSemanticContentRespDto();
         String retConent = "";
         QuerySemanticEngineDetailReqDto querySemanticEngineDetailReqDto = new QuerySemanticEngineDetailReqDto();
         querySemanticEngineDetailReqDto.setTemplateSemanticEngineCode("CREATE_OVERDUE_BURNING_TIME_CONTENT");
         QuerySemanticEngineDetailRespDto querySemanticEngineDetailRespDto = fwCompTemplateEngineClient.querySemanticEngineDetail(querySemanticEngineDetailReqDto).getData();
         if(querySemanticEngineDetailRespDto!=null && querySemanticEngineDetailRespDto.getTemplateEngineTemplate()!=null){
             String timeDiffHours = "\\{timeDiffHours}";
             if(reqDto.getTimeDiffHours()!=null && !reqDto.getTimeDiffHours().isEmpty()){
                 bRetFlag = true;
                 retConent = querySemanticEngineDetailRespDto.getTemplateEngineTemplate().replaceAll(timeDiffHours,reqDto.getTimeDiffHours());
             }

             if(retConent!=null && !retConent.isEmpty()){
                 retConent = retConent.replaceAll("---","");
                 retConent = retConent.replaceAll("（）","");
                 retData.setObjectName(retConent);
             }

             if(bRetFlag){
                 return retData;
             }

         }
         return retData;
      }
/**
      * code:receptionService
      * name:M3-接收入参字段
      * desc:undefined
      * gen by moon at 11/10/2023, 4:07:54 AM
      *
      **/
     @Trace(operationName = "M3-接收入参字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementTypeCodeFieldsAcceptRespDto implementTypeCodeFieldsAccept(ImplementTypeCodeFieldsAcceptReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementTypeCodeFieldsAcceptRespDto.class);
      }
/**
      * code:receptionService
      * name:M3约定权限为1
      * desc:undefined
      * gen by moon at 11/12/2023, 4:11:20 AM
      *
      **/
     @Trace(operationName = "M3约定权限为1")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ObtainReceiveFieldRespDto obtainReceiveField(ObtainReceiveFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ObtainReceiveFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:M3接收上文出参字段
      * desc:undefined
      * gen by moon at 11/14/2023, 10:05:08 PM
      *
      **/
     @Trace(operationName = "M3接收上文出参字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementGainInParameterFieldsRespDto implementGainInParameterFields(ImplementGainInParameterFieldsReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementGainInParameterFieldsRespDto.class);
      }
/**
      * code:obtainPageTotals
      * name:M3-执行获取分页总条数（特殊方法）
      * desc:undefined
      * gen by moon at 12/5/2023, 12:22:55 AM
      *
      **/
     @Trace(operationName = "M3-执行获取分页总条数（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementObtainPageTotalsRespDto implementObtainPageTotals(ImplementObtainPageTotalsReqDto reqDto) {
         ImplementObtainPageTotalsRespDto retData = new ImplementObtainPageTotalsRespDto();
         retData.setTotals(0L);
         Page<?> page =  CommonFunctionHelper.getBaseInfoFromLocal().getPageInfo();
         if(page!=null){
             retData.setTotals(page.getTotal());
         }
        return retData;
      }
/**
      * code:receptionService
      * name:M3约定更新工作任务（进行中）场景语义引擎标识与消息模板标识
      * desc:undefined
      * gen by moon at 12/31/2023, 4:51:56 AM
      *
      **/
     @Trace(operationName = "M3约定更新工作任务（进行中）场景语义引擎标识与消息模板标识")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementSendMsgReceiverAcceptFieldRespDto implementSendMsgReceiverAcceptField(ImplementSendMsgReceiverAcceptFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementSendMsgReceiverAcceptFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:M3-约定状态字段
      * desc:undefined
      * gen by moon at 1/1/2024, 3:58:21 AM
      *
      **/
     @Trace(operationName = "M3-约定状态字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAcceptFieldUseWorkTaskRespDto implementAcceptFieldUseWorkTask(ImplementAcceptFieldUseWorkTaskReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementAcceptFieldUseWorkTaskRespDto.class);

      }
/**
      * code:receptionService
      * name:M3约定协同内容类型为周期阶段资料
      * desc:undefined
      * gen by moon at 1/2/2024, 6:40:17 PM
      *
      **/
     @Trace(operationName = "M3约定协同内容类型为周期阶段资料")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementFourthReceivingFieldRespDto implementFourthReceivingField(ImplementFourthReceivingFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementFourthReceivingFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:M3接收入参字段
      * desc:undefined
      * gen by moon at 5/10/2024, 2:25:13 AM
      *
      **/
     @Trace(operationName = "M3接收入参字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementElevenReceivingFieldRespDto implementElevenReceivingField(ImplementElevenReceivingFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementElevenReceivingFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:M3约定系统当前时间
      * desc:undefined
      * gen by moon at 7/24/2024, 10:05:38 PM
      *
      **/
     @Trace(operationName = "M3约定系统当前时间")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementEightReceivingFieldRespDto implementEightReceivingField(ImplementEightReceivingFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementEightReceivingFieldRespDto.class);
      }
/**
      * code:objectToData
      * name:M3资料图片转数据集
      * desc:undefined
      * gen by moon at 9/16/2024, 11:40:45 AM
      *
      **/
     @Trace(operationName = "M3资料图片转数据集")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementPicMultipleSetDataEntryRespDto implementPicMultipleSetDataEntry(ImplementPicMultipleSetDataEntryReqDto reqDto) {
         ImplementPicMultipleSetDataEntryRespDto retData = new ImplementPicMultipleSetDataEntryRespDto();
         if (reqDto.getPicMultipleSetDataEntryList() == null || reqDto.getPicMultipleSetDataEntryList().size() <= 0) {
             return retData;
         }
         for (PicMultipleSetDataEntryDto oneSrc : reqDto.getPicMultipleSetDataEntryList()) {
             if (oneSrc.getDatasetField() != null && !oneSrc.getDatasetField().isEmpty()) {
                 String[] fileListSplit = oneSrc.getDatasetField().split(",");
                 if (fileListSplit != null && fileListSplit.length > 0) {
                     for (String oneFile : fileListSplit) {
                         if(oneFile.equals("--")){
                             continue;
                         }
                         PicMultipleSetDataEntryDto elm = new PicMultipleSetDataEntryDto();
                         elm.setCycleStageDataId(oneSrc.getCycleStageDataId());
                         elm.setDatasetPrimarykey(CommonFunctionHelper.getFilePath(oneFile));
                         retData.getPicMultipleSetDataEntryList().add(elm);
                     }
                 }
             }
         }
         return retData;
      }
  //手工接入方法
}
